const app = getApp();
import { jiatuiRequest } from "/utils/requests";
let page = 1, pageSize=150, id=0;
Page({
  data: {
    list: [],
    more: false,
  },
  async onLoad(options) {
    id = options.id;
    await this.getParticipants(id, page)
  },

  async getParticipants(activity_id, page){
    return new Promise(resolve => {
      jiatuiRequest({
        url: `/api/v1/lottery/getParticipants`,
        method: "GET",
        dataType: "jsonp",
        header: {
          "X-Requested-From": "WeChatMiniProgram",
        },
        data: {
          activity_id,
          page,
          pageSize
        },
      }).then(res => {
        const { code, data } = res;
        if (code !== 0) {
          xhs.showToast({
            title: '服务器错误',
            icon: "fail",
            duration: 1500,
            mask: true,
          });
        }
        let { list, total } = data;
        this.setData({
          list: [...this.data.list, ...list],
          total,
          allPage: Math.ceil(total/pageSize),
          more: Math.ceil(total/pageSize) == page ? false : true
        })
      }).catch(err => {
        console.log(err)
      })
    })
  },

  async more(){
    page++;
    await this.getParticipants(id, page)
  }
})